package com.acwing.partition15;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/3/19 8:58
 */
public class AC1442单词处理器 {

    private static int n, k;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        k = Integer.parseInt(ss[1]);
        ss = reader.readLine().split(" ");
        int row = k;
        for (int i = 0; i < n; ) {
            if (ss[i].length() <= row) {
                writer.write(ss[i] + " ");
                row -= ss[i].length();
                i++;
            } else {
                row = k;
                writer.write("\n");
            }
        }
        writer.flush();
    }
}
